//
//  WebSocketStartResult.swift
//  JiaoZiTaxi
//
//  Created by Hu Gang on 2022/10/11.
//

import Foundation

struct WebSocketStartResult: Codable {

  var cmd            : String? = nil
  var detectionId    : Int?    = nil
  var driver         : StartDriver? = StartDriver()
  var endLat         : Int?    = nil
  var endLon         : Int?    = nil
  var endTimestamp   : Int?    = nil
  var mydistance     : Int?    = nil
  var peopleId       : String? = nil
  var price          : Int?    = nil
  var receiverId     : String? = nil
  var renshu         : Int?    = nil
  var sended         : Int?    = nil
  var shijirenshu    : Int?    = nil
  var startLat       : Int?    = nil
  var startLon       : Int?    = nil
  var startTimestamp : Int?    = nil
  var status         : String? = nil
  var subCmd         : String? = nil

  enum CodingKeys: String, CodingKey {

    case cmd            = "cmd"
    case detectionId    = "detectionId"
    case driver         = "driver"
    case endLat         = "end_lat"
    case endLon         = "end_lon"
    case endTimestamp   = "end_timestamp"
    case mydistance     = "mydistance"
    case peopleId       = "peopleId"
    case price          = "price"
    case receiverId     = "receiverId"
    case renshu         = "renshu"
    case sended         = "sended"
    case shijirenshu    = "shijirenshu"
    case startLat       = "start_lat"
    case startLon       = "start_lon"
    case startTimestamp = "start_timestamp"
    case status         = "status"
    case subCmd         = "subCmd"

  }

  init(from decoder: Decoder) throws {
    let values = try decoder.container(keyedBy: CodingKeys.self)

    cmd            = try values.decodeIfPresent(String.self , forKey: .cmd            )
    detectionId    = try values.decodeIfPresent(Int.self    , forKey: .detectionId    )
    driver         = try values.decodeIfPresent(StartDriver.self , forKey: .driver         )
    endLat         = try values.decodeIfPresent(Int.self    , forKey: .endLat         )
    endLon         = try values.decodeIfPresent(Int.self    , forKey: .endLon         )
    endTimestamp   = try values.decodeIfPresent(Int.self    , forKey: .endTimestamp   )
    mydistance     = try values.decodeIfPresent(Int.self    , forKey: .mydistance     )
    peopleId       = try values.decodeIfPresent(String.self , forKey: .peopleId       )
    price          = try values.decodeIfPresent(Int.self    , forKey: .price          )
    receiverId     = try values.decodeIfPresent(String.self , forKey: .receiverId     )
    renshu         = try values.decodeIfPresent(Int.self    , forKey: .renshu         )
    sended         = try values.decodeIfPresent(Int.self    , forKey: .sended         )
    shijirenshu    = try values.decodeIfPresent(Int.self    , forKey: .shijirenshu    )
    startLat       = try values.decodeIfPresent(Int.self    , forKey: .startLat       )
    startLon       = try values.decodeIfPresent(Int.self    , forKey: .startLon       )
    startTimestamp = try values.decodeIfPresent(Int.self    , forKey: .startTimestamp )
    status         = try values.decodeIfPresent(String.self , forKey: .status         )
    subCmd         = try values.decodeIfPresent(String.self , forKey: .subCmd         )

  }

  init() {

  }

}

struct StartDriver: Codable {

  var address       : String? = nil
  var age           : Int?    = nil
  var agree         : Int?    = nil
  var carLat        : Double? = nil
  var carLon        : Double? = nil
  var carType       : String? = nil
  var chepai        : String? = nil
  var cmd           : String? = nil
  var distance      : Int?    = nil
  var fanwei        : Int?    = nil
  var jianceHangye  : String? = nil
  var jianceXingzhi : Int?    = nil
  var laosPhone     : String? = nil
  var lat           : Double? = nil
  var lon           : Double? = nil
  var name          : String? = nil
  var online        : Int?    = nil
  var openid        : String? = nil
  var peopleId      : String? = nil
  var phone         : String? = nil
  var sex           : Int?    = nil
  var status        : Int?    = nil
  var validate      : Int?    = nil
  var zans          : Int?    = nil

  enum CodingKeys: String, CodingKey {

    case address       = "address"
    case age           = "age"
    case agree         = "agree"
    case carLat        = "car_lat"
    case carLon        = "car_lon"
    case carType       = "car_type"
    case chepai        = "chepai"
    case cmd           = "cmd"
    case distance      = "distance"
    case fanwei        = "fanwei"
    case jianceHangye  = "jiance_hangye"
    case jianceXingzhi = "jiance_xingzhi"
    case laosPhone     = "laos_phone"
    case lat           = "lat"
    case lon           = "lon"
    case name          = "name"
    case online        = "online"
    case openid        = "openid"
    case peopleId      = "peopleId"
    case phone         = "phone"
    case sex           = "sex"
    case status        = "status"
    case validate      = "validate"
    case zans          = "zans"

  }

  init(from decoder: Decoder) throws {
    let values = try decoder.container(keyedBy: CodingKeys.self)

    address       = try values.decodeIfPresent(String.self , forKey: .address       )
    age           = try values.decodeIfPresent(Int.self    , forKey: .age           )
    agree         = try values.decodeIfPresent(Int.self    , forKey: .agree         )
    carLat        = try values.decodeIfPresent(Double.self , forKey: .carLat        )
    carLon        = try values.decodeIfPresent(Double.self , forKey: .carLon        )
    carType       = try values.decodeIfPresent(String.self , forKey: .carType       )
    chepai        = try values.decodeIfPresent(String.self , forKey: .chepai        )
    cmd           = try values.decodeIfPresent(String.self , forKey: .cmd           )
    distance      = try values.decodeIfPresent(Int.self    , forKey: .distance      )
    fanwei        = try values.decodeIfPresent(Int.self    , forKey: .fanwei        )
    jianceHangye  = try values.decodeIfPresent(String.self , forKey: .jianceHangye  )
    jianceXingzhi = try values.decodeIfPresent(Int.self    , forKey: .jianceXingzhi )
    laosPhone     = try values.decodeIfPresent(String.self , forKey: .laosPhone     )
    lat           = try values.decodeIfPresent(Double.self , forKey: .lat           )
    lon           = try values.decodeIfPresent(Double.self , forKey: .lon           )
    name          = try values.decodeIfPresent(String.self , forKey: .name          )
    online        = try values.decodeIfPresent(Int.self    , forKey: .online        )
    openid        = try values.decodeIfPresent(String.self , forKey: .openid        )
    peopleId      = try values.decodeIfPresent(String.self , forKey: .peopleId      )
    phone         = try values.decodeIfPresent(String.self , forKey: .phone         )
    sex           = try values.decodeIfPresent(Int.self    , forKey: .sex           )
    status        = try values.decodeIfPresent(Int.self    , forKey: .status        )
    validate      = try values.decodeIfPresent(Int.self    , forKey: .validate      )
    zans          = try values.decodeIfPresent(Int.self    , forKey: .zans          )

  }

  init() {

  }

}
